package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 处理根路径
        registry.addViewController("/").setViewName("forward:/index.html");

        // 捕获所有非API且非静态资源的路径（排除/index.html）
        registry.addViewController("/{path:^(?!api|static|index\\.html|error).*$}/**")
                .setViewName("forward:/index.html");
    }
}
